﻿using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
using ZhangBY.Data;
using ZhangBY.Entity;
using ZhangBY.Data.IDbSupplier;

namespace ZhangBY.Data.SqlServer
{
    public class DataProvider : IDataSupplier
    {
        /// <summary>
        /// 根据用户名查找用户信息并用户返回ID
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public object GetUserIdByUserName(ShortUserInfo user)
        {
            DbParameter parms = DBHelper.CreateInParam("@username", (DbType)SqlDbType.NVarChar, user.UserName);
            string commandText = "SELECT * FROM [dbo].[zby_u_user] WHERE [username]=@username";
            return DBHelper.ExecuteScalar(CommandType.Text, commandText, parms);
        }
        /// <summary>
        /// 根据用户名查找用户信息
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public DataTable GetUserByUserName(ShortUserInfo user)
        {
            DbParameter parms = DBHelper.CreateInParam("@username", (DbType)SqlDbType.NVarChar, user.UserName);
            string commandText = "SELECT * FROM [dbo].[zby_u_user] WHERE [username]=@username";
            return DBHelper.ExecuteDataSet(CommandType.Text,commandText,parms).Tables[0];                                  
        }
        /// <summary>
        /// 根据用户名和密码查找用户信息
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public DataTable GetUserByUserNameAndUserPass(ShortUserInfo user)
        {
            DbParameter[] parms = {
                                      DBHelper.CreateInParam("@username", (DbType)SqlDbType.NVarChar, user.UserName),
                                      DBHelper.CreateInParam("@userpass", (DbType)SqlDbType.NVarChar, user.UserPass)
                                  };
            string commandText = "SELECT * FROM [dbo].[zby_u_user] WHERE [username]=@username AND [userpass]=@userpass";
            return DBHelper.ExecuteDataSet(CommandType.Text, commandText, parms).Tables[0];
        }
    }
}
